package com.runa.rccprotocol.dto.tiger;

import com.runa.protocol.util.ByteUtil;
import com.runa.protocol.util.DigitalUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * 2024/12/24 16:28
 * zhangYB
 * 泰德尔
 */
@Data
@Slf4j
public class TigerValveRequestData {


    public byte[] read(int slaveId, int address, int count) {
        byte[] data = new byte[8];
        int i = 0;
        data[i++] = (byte)(slaveId & 0xff);
        data[i++] = 0x03;

        data[i++] = (byte)(address >> 8 & 0xff);
        data[i++] = (byte)(address & 0xff);

        data[i++] = (byte)(count >> 8 & 0xff);
        data[i++] = (byte)(count & 0xff);

        int crc = DigitalUtil.calcCrc16(data, i);
        data[i++] = (byte) (crc & 0xff);
        data[i++] = (byte) (crc >> 8);

        return data;
    }


    public static void main(String[] args) {
        String netSerial = "00819676";
        TigerValveRequestData requestData = new TigerValveRequestData();
        byte[] read = requestData.read(9, 1, 31);
        log.info("抄阀: {}", ByteUtil.byteToHexString(read));

    }







}
